package com.example.test.util;

import com.example.test.bean.BasicArea;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

public class MybatisUtil {
    // SSM
    public static void main(String[] args) {
//      String resource = "mybatis-config.xml";
        String resource = "";
        try{
            //加载Mybatis的配置文件
            Reader reader = Resources.getResourceAsReader(resource);
            //构建sqlSession的工厂
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
            //创建可以执行sql的SqlSession
            SqlSession session = sessionFactory.openSession();
            //映射sql的标志字符串
            String statement = "com.example.test.mapper.BasicAreaMapper.selectByPrimaryKey";
            //执行查询返回id为1的User对象
            BasicArea basicArea = session.selectOne(statement,"1385128181660438529");
            System.out.println(basicArea);

        }catch (Exception e) {
            e.printStackTrace();
        }

    }
}
